Ext.require(  
        [  
            'Ext.grid.*',  
            'Ext.toolbar.Paging',  
            'Ext.util.*',  
            'Ext.data.*',  
            //注意引用  
            'Ext.ux.form.SearchField'  
         ]          
);
	var downloadTeacherId=0;
	
downloadFile = function(){
	
	var inputNum = 0;
	Ext.define('teacherModel',{
		extend:'Ext.data.Model',
		fields:[
		        	{name:'teacherId',type:'String'},
		        	{name:'teacherName',type:'string'},
		        	{name:'account',type:'string'},
			        {name:'password',type:'string'},
			        {name:'passwordAppend',type:'string'},
			        {name:'job',mapping:'job.valueId',type:'string'},
			        {name:'political',mapping:'political.valueId',type:'string'},
			        {name:'academy',mapping:'academy.valueId',type:'string'}
			       ],
		idProperty : 'teacherId'
	});
	var teacherJobForMStore  = Ext.create('Ext.data.Store',{
	       // xtype: 'Ext.data.Store',
	       // singleton : true,
	        proxy:{ 
	        	type:'ajax',
	        	url: 'publicDictAction.action',      
	        	reader: { 
	        		type: 'json', 
	        		root: 'list' 
	        	},
	        	extraParams:{
	        		publicCode:'teacher job'
	        	}
	        },
	        fields:['valueId','valueName'],
	        autoLoad: true       
	    });

	
	var teacherAcademyForMStore  = Ext.create('Ext.data.Store',{
	    // xtype: 'Ext.data.Store',
	     //singleton : true,
	     proxy:{ 
	     	type:'ajax',
	     	url: 'publicDictAction.action' ,      
	     	reader: { 
	     		type: 'json', 
	     		root: 'list' 
	     	},
	     	extraParams:{
	     		publicCode:'academy'
	     	}
	     },
	     fields:['valueId','valueName'],
	     autoLoad: true        
	 });

	var store = Ext.create('Ext.data.Store',{
		pageSize:10,
		model:teacherModel,
		autoLoad:true,
		proxy:{
			type:'ajax',
			url:'searchAllTeacherAction.action',
			reader:{
				type:'json',
				root:'resultList.list',
				totalProperty:'resultList.total'
			}
		}
	});
	
	//
	var search = {
			width:300,
			fieldLabel:'搜索',
			labelWidth:70,
			xtype:'searchfield',
			store:store			
		};
	//结果列表
	var grid = Ext.create('Ext.grid.Panel',{
		store:store,	
		columnLines:true,
		disableSelection:false,
		//width:600,
		loadMask:true,
		
		columns:[
		         {xtype: 'rownumberer',text:'序号',width:40},
		         {text:'编号',width:150,dataIndex:'teacherId',sortable:true,hidden:true},
		         {text:'姓名',width:150,dataIndex:'teacherName',sortable:true},
		         {text:'账号',width:150,dataIndex:'account',sortable:true},
		         {text:"职称",width:150,dataIndex:'job',sortable:true,
		        	 renderer:function(v){
		        			 var index = teacherJobForMStore.find('valueId',v); 
		        			 if(index != -1){
		        				 var r = teacherJobForMStore.getAt(index);
		        				 return r.get("valueName");
		        			 }
		        			 else{
		        				 return v;
		        			 }
		        	 } 
		        },
		         {text:"学院",width:150,dataIndex:'academy',sortable:true,
		        	renderer:function(v){
		        			 var index = teacherAcademyForMStore.find('valueId',v); 
		        			 if(index != -1){
		        				 var r = teacherAcademyForMStore.getAt(index);
		        				 return r.get("valueName");
		        			 }
		        			 else{
		        				 return v;
		        			 }
		        		 } 
		         }
		         ],
		autoHeight:true,
		authWidth:true,

		title:"导师列表",
		loadMask:true,
		pageSize:5,
		dockedItems:[
		{
			dock:'top',
			xtype:'toolbar',
			items:[search,
				{
					xtype:'label',
					html:'<div style="font-size:12px;color:red">*支持导师姓名的模糊查询</div>'
				}
			]
		},
		{
			dock:'bottom',
			xtype:'pagingtoolbar',	
			store:store,
			displayInfo:true,
			displayMsg:'显示{0}-{1}条，共计{2}条',
			emptyMsg:"没有数据"
		},{
			dock:'bottom',
			xtype:'label',
			html:'<div style="font-size:12px;color:red">双击导师信息进入资料下载页面</div>'
		}
		],
		listeners:{  
			//双击事件
			itemdblclick : function( grid, record, item, index, e, eOpts){  
				var selectedKeys = grid.getSelectionModel().getSelection();
				newWindow(selectedKeys[0]);
			       }  
		}
	});

	function newWindow(record){
		
		var edit = Ext.create('Ext.Window',{
			id:'inputPassword',
			layout:'form',
			width:350,
			height:150,
			//closeAction:'hide',
			plain:true,
			modal: true,
			resizable : false,
			title:'导师：'+record.get('teacherName'),
			items:[{
				xtype:'textfield',
				id:'passwordAppend',
				hidden:true,
				listeners: {
		               'afterrender': function () {
		            	   //Ext.Msg.alert("ss",record);
		                   if (record!=null && record != false){
		                	   this.setValue(record.get('passwordAppend'));
		                   }
		               }
		           }
			},{
					   xtype:'textfield',  
			           fieldLabel:'请输入下载密码', 
			          // width:400,
			           id:'inPassword',
			           name:'inPassword',  
			           inputType: 'password',
			           allowBlank:true
				}],
			buttons : [ {
				xtype : "button",
				text : "确认",
				pressed : false,
				handler : function(){
					if(checkPass()){
						openDownpage(record.get('teacherId'));
						Ext.getCmp('inputPassword').close();
					}
					
				}
			}],
		buttonAlign : "center",
		plain:true
			
		});
		edit.show();
	}
	
	function checkPass(){
		var inPassword = Ext.getCmp('inPassword').getValue();
		var passwordAppend = Ext.getCmp('passwordAppend').getValue();
		
		if(inPassword != passwordAppend){
			inputNum++;
			if(inputNum >= 5){
				Ext.getCmp('inputPassword').close();
				return false;
			}
			Ext.Msg.alert("提示","密码错误,"+"你还有"+(5-inputNum)+"机会输入密码！");
			return false;
		}
		
		return true;
	}
	
	function openDownpage(Tid){
		var tabId = "teacherData"+Tid;
		downloadTeacherId = Tid;
		var funActive = eval(' new downPage');
		var tab = center.queryById(tabId);
        if (!tab){
        //	teacherId = id;
        	var tab = center.add({
    	        id: tabId,  
    	        xtype: "panel",
    	        title: '资料下载',
    	       // baseCls:'allBackImage',
    	        closable: true,
    	        maskDiabled: true,
    	        frame: true,
    	        autoScroll : true,
    	        items:funActive
    	    });
        }
        
        center.setActiveTab(tabId);
	}
	return grid;
	
	
	
}